package ch.bfh.abcmmh.model.cars.specialVehicles;

import java.util.Observable;

import ch.bfh.abcmmh.controller.operating.clock.Clock;
import ch.bfh.abcmmh.controller.operating.scanner.StreetScanner;
import ch.bfh.abcmmh.exceptions.EndofStreetExeption;
import ch.bfh.abcmmh.exceptions.WrongSpeedException;
import ch.bfh.abcmmh.model.cars.Vehicle;
import ch.bfh.abcmmh.model.street.Street;

public class Bus extends Vehicle{
	
	private static int BUSLENGTH = 50;

	public Bus(Street street, int startSpeed, int position, int carNumber) {
		super(street, startSpeed, position, carNumber, BUSLENGTH);
		this.maxSpeed = 80;
	}

	@Override
	public void update(Observable o, Object arg) {
		
		this.accelerate();
		
		this.slowdown(this.calculateSlowdown(new StreetScanner(street)));
		
		// no dawdle
		
		try {
			this.move();
		} catch (WrongSpeedException e) {
		} catch (EndofStreetExeption e) {
			Clock c = (Clock) o;
			c.deleteObserver(this);
			this.onStreet= false;
		}
	}

}
